package com.zkjl.protect_business.controller;


import com.zkjl.protect_business.common.ApiResponse;
import com.zkjl.protect_business.dto.PageBaseDTO;
import com.zkjl.protect_business.service.SiteSearchService;
import com.zkjl.protect_business.utils.ResultUtil;
import com.zkjl.protect_business.vo.SearchResultVO;
import com.zkjl.protect_business.vo.SiteSearchVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/siteSearchs")
@Api(tags = {"站内搜索"})
public class SiteSearchContoller {

    @Autowired
    SiteSearchService siteSearchService;

    @ApiOperation(value = "站内搜索", notes = "站内搜索", httpMethod = "GET")
    @GetMapping(value = "group")
    ApiResponse<List<SiteSearchVO>> search(String search) {
        List<SiteSearchVO> search1 = siteSearchService.search(search);
        return ApiResponse.ofSuccess(search1);
    }

    @ApiOperation(value = "站内搜索分页结果", notes = "站内搜索分页结果 结果内的businessName表示数据归属哪个业务分内，hit 命中关键词 fields 所属业务的字段", httpMethod = "GET")
    @GetMapping
    ApiResponse<Map<String, Object>> search(PageBaseDTO pageBaseDTO,String businessId) {

        PageImpl<Map<String, Object>> search = siteSearchService.search(pageBaseDTO, businessId);

        return ResultUtil.successPagesVO(search);
    }


}
